import win32gui, win32con


def getWindowList():
	windowList = []
	win32gui.EnumWindows(_windowEnumerationHandler, windowList) 
	return windowList #note: yes, this is a weird way of doing this, but not my fault! blame the makers of win32gui
	
def _windowEnumerationHandler(hwnd, resultList):
	if win32gui.IsWindowVisible(hwnd) > 0: #visible check is to weed out a lot of nonsense windows
		try:
			title = win32gui.GetWindowText(hwnd)
			if title != '': #we don't care about windows without a title
				resultList.append([hwnd,title]) 
		except:
			pass #ignore errors

def showWindow(hwnd):
	win32gui.ShowWindow(hwnd,win32con.SW_SHOW)
	win32gui.ShowWindow(hwnd,win32con.SW_RESTORE) #in case it is minimized
